﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Ext.Net;
using System.Collections.Generic;

public partial class SYS_POPEDOM_Role_Create : BasePage
{
    private static int sub_system = 0;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            InitPageData(Request.QueryString["ObjId"]);
        }
    }

    private void CreatTmpTable()
    {
        DataTable alltable = new DataTable();
        alltable.TableName = "alltable";

        alltable.Columns.Add("MENU_NO", Type.GetType("System.String"));
        alltable.Columns.Add("MENU_NAME", Type.GetType("System.String"));
        alltable.Columns.Add("PARENT_MENU_NO", Type.GetType("System.String"));
        alltable.Columns.Add("INNER_NO", Type.GetType("System.String"));
        alltable.Columns.Add("IS_LEAF", Type.GetType("System.String"));
        alltable.Columns.Add("FLAG", Type.GetType("System.String"));

        ViewState["alltable"] = alltable;

        DataTable roletable = new DataTable();
        roletable.TableName = "roletable";

        roletable.Columns.Add("MENU_NO", Type.GetType("System.String"));
        roletable.Columns.Add("MENU_NAME", Type.GetType("System.String"));
        roletable.Columns.Add("PARENT_MENU_NO", Type.GetType("System.String"));
        roletable.Columns.Add("INNER_NO", Type.GetType("System.String"));
        roletable.Columns.Add("IS_LEAF", Type.GetType("System.String"));
        roletable.Columns.Add("FLAG", Type.GetType("System.String"));

        ViewState["roletable"] = roletable;
    }



    /// <summary>
    /// 构建弹出树数据集
    /// </summary>
    /// <param name="all_t"></param>
    /// <param name="accept_t"></param>
    /// <param name="no_t"></param>
    private void GetDataForDiff(DataTable all_t, DataTable role_t)
    {
        //递归leaf_t
        if (role_t.Rows.Count == 0)
        {
            ViewState["norole"] = all_t;
            return;
        }
        DataTable tmp = CommonLib.BLL.SYS_ROLE_FUNCTION.GetList("1<>1", "").Tables[0];

        DataRow[] func = all_t.Select("is_leaf=1");
        foreach (DataRow row in func)
        {
            if (role_t.Select("menu_no='" + row["menu_no"].ToString() + "'").Length == 0)
            {
                tmp.ImportRow(row);
                DataRow[] tmpDR = tmp.Select("parent_menu_no='" + row["menu_no"].ToString() + "' and sub_system=" + row["sub_system"].ToString());
                if (tmpDR.Length > 0)
                    continue;
                else
                {
                    int i = row["inner_no"].ToString().Length;
                    tmpDR = all_t.Select("inner_no like '" + row["inner_no"].ToString().Substring(0, 2) + "%' and is_leaf=0 and sub_system=" + row["sub_system"].ToString() + " and len(inner_no)<>" + i.ToString(), "inner_no desc");
                    foreach (DataRow prow in tmpDR)
                    {
                        if (tmp.Select("menu_no='" + prow["menu_no"].ToString() + "'").Length > 0)
                            break;
                        else
                        {
                            //只增加自己的上级
                            if (row["inner_no"].ToString().Length < prow["inner_no"].ToString().Length)
                                break;
                            if (row["inner_no"].ToString().Substring(0, prow["inner_no"].ToString().Length) == prow["inner_no"].ToString())
                                tmp.ImportRow(prow);
                        }
                    }
                }
            }
            //}
        }
        tmp.AcceptChanges();
        ViewState["norole"] = tmp;
    }


    #region 页面初始化加载函数





    private void InitPageData(string ObjId)
    {
        extTf_RoleID.Disabled = true;
        string sWhere = " (is_leaf=1 and menu_no in (SELECT distinct menu_no FROM SYS_ROLE_FUNCTION srf WHERE srf.ROLE_ID IN (SELECT sdr.ROLE_ID "
                        + "FROM SYS_DEPT_ROLES sdr WHERE sdr.MASTER_ID IN (SELECT sor.MASTER_ID "
                        + "FROM SYS_OPERATOR_ROLE sor WHERE sor.[USER_ID]='" + BS_LoginUserID + "')))) or is_leaf=0 ";
        DataTable alltable = CommonLib.BLL.SYS_MENU.GetAllMenu2(sWhere);
        DataTable roletable = null;
        ViewState["alltable"] = alltable;
        if (ObjId == "Add")
        {
            ViewState["role_id"] = "";
            extTf_Creator.Text = BS_LoginUserName;
            extTf_CreatorDept.Text = BS_LoginDeptName;
            roletable = CommonLib.BLL.SYS_ROLE_FUNCTION.GetList("1<>1").Tables[0];
            ViewState["roletable"] = roletable;
        }
        else
        {
            //角色信息
            DataTable roleDataTable = CommonLib.BLL.SYS_ROLES.GetList("role_id='" + ObjId + "'").Tables[0];
            foreach (DataRow dr_role in roleDataTable.Select())
            {
                extTf_RoleID.Text = dr_role["ROLE_ID"].ToString();
                extTf_RoleName.Text = dr_role["ROLE_NAME"].ToString();
                extTa_Notes.Text = dr_role["NOTES"].ToString();
                extTf_Creator.Text = dr_role["CREATOR_NAME"].ToString();
                extTf_CreatorDept.Text = dr_role["DEPT_NAME"].ToString();
                ViewState["role_id"] = ObjId;
                roletable = CommonLib.BLL.SYS_ROLE_FUNCTION.GetList(" role_id='" + ViewState["role_id"].ToString() + "'", "inner_no").Tables[0];
                ViewState["roletable"] = roletable;
                if (extTf_RoleID.Text.Trim() == "01" || extTf_RoleID.Text.Trim() == "02")   //系统内置的两个角色不能修改
                {
                    extTf_RoleName.Disabled = extTf_Creator.Disabled
                        = extTf_CreatorDept.Disabled = extTa_Notes.Disabled
                        = extBtn_Add.Hidden = extBtn_Delete.Hidden = extBtn_Save.Disabled = true;
                }
            }

        }
        GetDataForDiff(alltable, roletable);
    }
    #endregion

    #region 功能路径函数
    [DirectMethod]
    public void nodeClick(string nodeID, string nodeText)
    {
        extHid_NodeId.Value = nodeID;
        string text = nodeText;
        if (nodeID == "0")
        {

            //  extTti_FunPath.Text = extTti_FunPath.Text + "：" + text;
        }
        else
        {
            if (nodeID.Substring(0, 1) == "A")
            {
                sub_system = int.Parse(nodeID.Substring(1));
                // extTti_FunPath.Text = extTti_FunPath.Text + "：" + text;
            }
            else
            {
                CommonLib.Model.SYS_MENU modeMenu = CommonLib.BLL.SYS_MENU.GetModel(nodeID);
                if (modeMenu.PARENT_MENU_NO == "")
                {
                    text = GetOneMenuName(modeMenu.SUB_SYSTEM) + "/" + modeMenu.MENU_NAME;
                    //  extTti_FunPath.Text = extTti_FunPath.Text + "：" + text;

                }
                else
                {
                    string paths = modeMenu.MENU_NAME;
                    string menuNo = modeMenu.PARENT_MENU_NO;
                    CommonLib.Model.SYS_MENU ParentModeMenu = null;
                    do
                    {
                        ParentModeMenu = CommonLib.BLL.SYS_MENU.GetModel(menuNo);
                        paths = ParentModeMenu.MENU_NAME + "/" + paths;
                        menuNo = ParentModeMenu.PARENT_MENU_NO;
                    }
                    while (ParentModeMenu.PARENT_MENU_NO != "");
                    text = GetOneMenuName(modeMenu.SUB_SYSTEM) + "/" + paths;
                    // extTti_FunPath.Text = extTti_FunPath.Text + "：" + text;
                }
            }
        }

        BindGrid(ViewState["roletable"] as DataTable, extHid_NodeId.Value.ToString());
        popWindow.Title = "当前授权范围：" + text;
    }
    [DirectMethod]
    public void SeclectRead(string nodeID, string nodeText, string isCheckedAll, string curAllRecords)
    {
        int isReadOnly = 0;
        if (isCheckedAll == "true")
            isReadOnly = 1;
        DataTable tmptable = ViewState["roletable"] as DataTable;
        Dictionary<string, string>[] joins = JSON.Deserialize<Dictionary<string, string>[]>(curAllRecords);
        DataRow[] tRA = null;
        foreach (Dictionary<string, string> row in joins)
        {
            tRA = tmptable.Select("menu_no='" + row["MENU_NO"] + "'");
            tRA[0]["readonly"] = isReadOnly;
            tRA[0].AcceptChanges();

        }
        Session["update"] = tmptable;
        nodeClick(nodeID, nodeText);
    }
    private string GetOneMenuName(int sub_system)
    {
        string oneMenuName = "";
        switch (sub_system)
        {
            case 1:
                oneMenuName = "生产管理";
                break;
            case 2:
                oneMenuName = "营销管理";
                break;
            case 3:
                oneMenuName = "行政办公";
                break;
            case 4:
                oneMenuName = "客服管理";
                break;
            case 5:
                oneMenuName = "决策支持";
                break;
            case 6:
                oneMenuName = "供电所";
                break;
        }
        return oneMenuName;
    }
    #endregion


    protected void extBtn_AddClick(object sender, DirectEventArgs e)
    {
        popWindow.Show();
    }

    [DirectMethod]
    public void ShowData(string aa)
    {

        X.Msg.Alert("提示", aa).Show();
        return;
    }

    [DirectMethod]
    public void refrashDataEvent(string MenuNodeIds)
    {
        //保存新增事件
        if (Session["update"] != null)
        {
            ViewState["roletable"] = Session["update"];
            Session["update"] = null;
        }
        SetDataToView(MenuNodeIds);
    }


    private void SetDataToView(string NodeIds)
    {
        DataTable tmptable = ViewState["roletable"] as DataTable;
        DataTable alltable = ViewState["alltable"] as DataTable;
        string[] menuno = NodeIds.Split(';');
        for (int i = 0; i < menuno.Length; i++)
        {
            string menu_no = menuno[i];
            if (menu_no.Substring(0, 1) == "A")   //选中的为子系统

            {
                DataRow[] tDr = alltable.Select("sub_system='" + menu_no.Substring(1) + "' and is_leaf=1");
                foreach (DataRow prow in tDr)
                {
                    DataRow tt = prow;
                    if (tmptable.Select("menu_no='" + prow["menu_no"] + "'").Length < 1)
                        tmptable.ImportRow(prow);
                }
            }
            else
            {
                DataRow[] t = alltable.Select("menu_no='" + menuno[i] + "'");
                DataRow[] tDr = alltable.Select("inner_no like '" + t[0]["inner_no"] + "%' and sub_system=" + t[0]["sub_system"] + " and is_leaf=1");
                foreach (DataRow prow in tDr)
                {
                    if (tmptable.Select("menu_no='" + prow["menu_no"] + "'").Length < 1)
                        tmptable.ImportRow(prow);
                }
            }
        }
        tmptable.AcceptChanges();
        ViewState["roletable"] = tmptable;
        GetDataForDiff(alltable, tmptable);
        BindGrid(tmptable, extHid_NodeId.Value.ToString());

    }

    private void BindGrid(DataTable r_table, string menu_no)
    {
        if (menu_no == "0")
        {
            this.Store1.DataSource = r_table;
        }
        else
        {

            if (menu_no.Substring(0, 1) == "A")
            {
                r_table.DefaultView.RowFilter = "sub_system=" + menu_no.Substring(1);
                this.Store1.DataSource = r_table;

            }
            else
            {

                DataRow[] t = (ViewState["alltable"] as DataTable).Select("menu_no='" + menu_no + "'");
                r_table.DefaultView.RowFilter = "inner_no like '" + t[0]["inner_no"] + "%' and sub_system=" + t[0]["sub_system"];
                // DataRow[] tDr = r_table.Select("inner_no like '" + t[0]["inner_no"] + "%' and sub_system=" + t[0]["sub_system"]);
                this.Store1.DataSource = r_table;

            }
        }
        this.Store1.DataBind();
        //SelectFristData(GridPanel1, r_table, "");
    }

    protected void extBtn_SaveClick(object sender, DirectEventArgs e)
    {
        if (extTf_RoleName.Text.Trim() == "")
        {
            X.Msg.Alert("提示", "角色名称不能为空！").Show();
            return;
        }
        if (SaveData())
            X.Msg.Alert("提示", "保存成功！").Show();
        else
            X.Msg.Alert("提示", "保存失败！").Show();
    }

    protected void DelFunc(object sender, DirectEventArgs e)
    {
        int nCount = 0;
        RowSelectionModel sm = this.GridPanel1.SelectionModel.Primary as RowSelectionModel;
        nCount = sm.SelectedRows.Count;
        if (nCount == 0)
        {
            X.Msg.Alert("系统提示", "请先选择要删除的记录！").Show();
            return;
        }
        DataTable tmptable = ViewState["roletable"] as DataTable;
        foreach (SelectedRow row in sm.SelectedRows)
        {
            DataRow[] tR = tmptable.Select("menu_no='" + row.RecordID + "'");
            tmptable.Rows.Remove(tR[0]);
        }
        tmptable.AcceptChanges();
        ViewState["roletable"] = tmptable;
        GetDataForDiff(ViewState["alltable"] as DataTable, tmptable);

        BindGrid(tmptable, extHid_NodeId.Value.ToString());
        //处理数据

    }

    protected void Store1_BeforeRecordUpdated(object sender, BeforeRecordUpdatedEventArgs e)
    {
        object region = e.NewValues["READONLY"];
        string menu_no = e.Keys["MENU_NO"].ToString();
        Int16 r_only = Convert.ToInt16(Convert.ToBoolean(region));
        DataTable tmptable = ViewState["roletable"] as DataTable;
        DataRow[] tR = tmptable.Select("menu_no='" + menu_no + "'");
        tR[0]["readonly"] = r_only;
        tR[0].AcceptChanges();

        // ViewState["roletable"] = tmptable;
        Session["update"] = tmptable;
    }



    private bool SaveData()//保存数据
    {
        if (extTf_RoleID.Text.Trim() == "01" || extTf_RoleID.Text.Trim() == "02")   //系统内置的两个角色不能修改   
        {
            return false;
        }

        bool tmp = true;
        //CheckReadChange();
        string _roleID = extTf_RoleID.Text.Trim();

        //角色信息
        CommonLib.Model.SYS_ROLES Model_Roles = new CommonLib.Model.SYS_ROLES();
        if (ViewState["role_id"].ToString() != "")
        {
            Model_Roles = CommonLib.BLL.SYS_ROLES.GetModel(extTf_RoleID.Text.Trim());
        }
        else
        {
            DataTable dt = CommonLib.BLL.SYS_ROLES.GetList("role_id='" + extTf_RoleID.Text.Trim() + "'").Tables[0];
            if (dt.Rows.Count > 0)
            {
                X.Msg.Alert("提示", "保存失败，角色代码不能重复！").Show();
                tmp = false;
                return tmp;
            }
            Model_Roles.ROLE_ID = CommonLib.BLL.SYS_ROLES.GetNewID().ToString("0000");
            extTf_RoleID.Text = Model_Roles.ROLE_ID;
            Model_Roles.CREATOR = BS_LoginUserID;
            Model_Roles.DEPT_ID = BS_LoginDeptId;
            Model_Roles.DEL_FLAG = 0;
        }
        Model_Roles.ROLE_NAME = extTf_RoleName.Text;
        Model_Roles.NOTES = extTa_Notes.Text;

        //角色功能信息
        if (Session["update"] != null)
        {
            ViewState["roletable"] = Session["update"];
            Session["update"] = null;
        }
        DataTable RoleFunnTable = ViewState["roletable"] as DataTable;
        CommonLib.Model.SYS_ROLE_FUNCTION[] fun_models = null;
        if (RoleFunnTable != null)
        {
            fun_models = new CommonLib.Model.SYS_ROLE_FUNCTION[RoleFunnTable.Rows.Count];
            for (int i = 0; i < RoleFunnTable.Rows.Count; i++)
            {
                CommonLib.Model.SYS_ROLE_FUNCTION fun_model = new CommonLib.Model.SYS_ROLE_FUNCTION();
                fun_model.MENU_NO = RoleFunnTable.Rows[i]["MENU_NO"].ToString();
                fun_model.ROLE_ID = Model_Roles.ROLE_ID;
                fun_model.READONLY = Convert.ToInt16(RoleFunnTable.Rows[i]["READONLY"]);
                fun_models[i] = fun_model;
            }
        }
        //保存
        if (ViewState["role_id"].ToString() == "")
        {
            if (CommonLib.BLL.SYS_ROLES.AddTrans(Model_Roles, fun_models) > 0)
                ViewState["role_id"] = Model_Roles.ROLE_ID;
            else
                tmp = false;
        }
        else
        {
            if (CommonLib.BLL.SYS_ROLES.UpdateTrans(Model_Roles, fun_models) <= 0)
                tmp = false;
        }
        return tmp;
    }

    [DirectMethod]
    public string NodeLoad(string nodeID)
    {

        Ext.Net.TreeNodeCollection nodes = new Ext.Net.TreeNodeCollection();
        if (!string.IsNullOrEmpty(nodeID))
        {
            DataTable TmpTable = null;
            if (nodeID == "0")
            {
                TmpTable = CommonLib.BLL.SYS_SUBSYSTEM.GetList("sub_system in (select DISTINCT SUB_SYSTEM"
                + " from SYS_MENU where menu_no in (SELECT distinct menu_no FROM SYS_ROLE_FUNCTION srf WHERE srf.ROLE_ID IN (SELECT sdr.ROLE_ID FROM SYS_DEPT_ROLES sdr WHERE sdr.MASTER_ID IN (SELECT sor.MASTER_ID FROM SYS_OPERATOR_ROLE sor "
                + " WHERE sor.[USER_ID]='admin'))))").Tables[0];
                for (int i = 0; i < TmpTable.Rows.Count; i++)
                {
                    AsyncTreeNode asyncNode = new AsyncTreeNode();
                    asyncNode.Text = TmpTable.Rows[i]["system_name"].ToString();
                    asyncNode.NodeID = "A" + TmpTable.Rows[i]["sub_system"].ToString();
                    asyncNode.IconCls = "no-Icon";
                    nodes.Add(asyncNode);
                }
            }
            else
            {
                string sql = "";
                if (nodeID.Substring(0, 1) == "A")
                {
                    int subsystem = int.Parse(nodeID.Substring(1));
                    sql = "(parent_menu_no='' OR parent_menu_no is null)  and sub_system=" + subsystem;
                }
                else
                {
                    sql = "parent_menu_no='" + nodeID + "'";
                    sql += "and ( (is_leaf=1 and menu_no in (SELECT distinct menu_no FROM SYS_ROLE_FUNCTION srf WHERE srf.ROLE_ID IN (SELECT sdr.ROLE_ID "
                        + "FROM SYS_DEPT_ROLES sdr WHERE sdr.MASTER_ID IN (SELECT sor.MASTER_ID "
                        + "FROM SYS_OPERATOR_ROLE sor WHERE sor.[USER_ID]='" + BS_LoginUserID + "')))) or is_leaf=0)";
                }

                TmpTable = CommonLib.BLL.SYS_MENU.GetList(sql).Tables[0];
                for (int i = 0; i < TmpTable.Rows.Count; i++)
                {
                    if (!Convert.ToBoolean(TmpTable.Rows[i]["is_leaf"]))
                    {
                        AsyncTreeNode asyncNode = new AsyncTreeNode();
                        asyncNode.Text = TmpTable.Rows[i]["menu_name"].ToString();
                        asyncNode.NodeID = TmpTable.Rows[i]["menu_no"].ToString();
                        asyncNode.IconCls = "no-Icon";
                        nodes.Add(asyncNode);
                    }
                    else
                    {
                        Ext.Net.TreeNode treeNode = new Ext.Net.TreeNode();
                        treeNode.Text = TmpTable.Rows[i]["menu_name"].ToString();
                        treeNode.NodeID = TmpTable.Rows[i]["menu_no"].ToString();
                        treeNode.Leaf = true;
                        treeNode.IconCls = "no-Icon";
                        nodes.Add(treeNode);
                    }
                }
            }
        }
        return nodes.ToJson();
    }


    #region  以下是弹出窗体代码

    [DirectMethod]
    public string RefreshMenu()
    {
        string nodeId = extHid_NodeId.Value.ToString();
        Ext.Net.TreeNodeCollection nodes = BuildTree(null, nodeId);
        return nodes.ToJson();
    }

    [DirectMethod]
    public string NodeLoadWin(string nodeID, bool ischeck)
    {
        Ext.Net.TreeNodeCollection nodes = new Ext.Net.TreeNodeCollection();
        DataTable tmp = ViewState["norole"] as DataTable;
        if (nodeID == "0")
        {
            DataTable tmptable = CommonLib.BLL.SYS_SUBSYSTEM.GetList("sub_system in (select DISTINCT SUB_SYSTEM"
                + " from SYS_MENU where menu_no in (SELECT distinct menu_no FROM SYS_ROLE_FUNCTION srf WHERE srf.ROLE_ID IN (SELECT sdr.ROLE_ID FROM SYS_DEPT_ROLES sdr WHERE sdr.MASTER_ID IN (SELECT sor.MASTER_ID FROM SYS_OPERATOR_ROLE sor "
                + " WHERE sor.[USER_ID]='" + BS_LoginUserID + "'))))").Tables[0];
            for (int i = 0; i < tmptable.Rows.Count; i++)
            {
                AsyncTreeNode asyncNode = new AsyncTreeNode();
                asyncNode.NodeID = "A" + tmptable.Rows[i]["sub_system"].ToString();
                if (tmp.Select("sub_system=" + tmptable.Rows[i]["sub_system"].ToString()).Length == 0)
                {
                    asyncNode.Text = tmptable.Rows[i]["system_name"].ToString();
                    asyncNode.Leaf = true;
                }
                else
                {
                    asyncNode.Text = tmptable.Rows[i]["system_name"].ToString();
                    asyncNode.Checked = ThreeStateBool.False;
                }
                asyncNode.Icon = Icon.Accept;
                nodes.Add(asyncNode);
            }
        }
        else
        {
            DataRow[] tRow = null;
            if (nodeID.Substring(0, 1) == "A")
            {
                string nodestr = nodeID.Substring(1);

                tRow = tmp.Select("sub_system=" + nodestr + " and (parent_menu_no is null or parent_menu_no='')");
            }
            else
                tRow = tmp.Select("parent_menu_no='" + nodeID + "'");

            foreach (DataRow tDr in tRow)
            {
                AsyncTreeNode asyncNode = new AsyncTreeNode();
                asyncNode.Text = tDr["menu_name"].ToString();
                asyncNode.NodeID = tDr["menu_no"].ToString();
                if (ischeck)
                    asyncNode.Checked = ThreeStateBool.True;
                else
                    asyncNode.Checked = ThreeStateBool.False;
                asyncNode.Icon = Icon.Accept;
                if (Convert.ToBoolean(tDr["is_leaf"]))
                {
                    asyncNode.Leaf = true;
                }

                nodes.Add(asyncNode);
            }
        }
        return nodes.ToJson();
    }

    private Ext.Net.TreeNodeCollection BuildTree(Ext.Net.TreeNodeCollection nodes, string nodeID)
    {
        DataTable TmpTable = null;
        if (nodes == null)
        {
            nodes = new Ext.Net.TreeNodeCollection();
        }
        if (nodeID == "0")
        {
            AsyncTreeNode asyncNode = new AsyncTreeNode();
            asyncNode.Text = "全部子系统";
            asyncNode.NodeID = "0";
            asyncNode.Checked = ThreeStateBool.False;
            asyncNode.IconCls = "no-Icon";
            nodes.Add(asyncNode);
        }
        else
        {
            DataTable tmp = ViewState["norole"] as DataTable;
            DataRow[] tRow = null;
            if (nodeID.Substring(0, 1) == "A")
            {
                string nodestr = nodeID.Substring(1);
                TmpTable = CommonLib.BLL.SYS_SUBSYSTEM.GetList("sub_system=" + nodestr).Tables[0];
                AsyncTreeNode asyncNode = new AsyncTreeNode();
                asyncNode.Text = TmpTable.Rows[0]["SYSTEM_NAME"].ToString();
                asyncNode.NodeID = "A" + TmpTable.Rows[0]["SUB_SYSTEM"].ToString();
                asyncNode.Checked = ThreeStateBool.False;
                asyncNode.IconCls = "no-Icon";
                nodes.Add(asyncNode);
            }
            else
            {
                tRow = tmp.Select("menu_no='" + nodeID + "'");
                if (tRow.Length > 0)
                {
                    AsyncTreeNode asyncNode = new AsyncTreeNode();
                    asyncNode.Text = tRow[0]["menu_name"].ToString();
                    asyncNode.NodeID = tRow[0]["menu_no"].ToString();
                    asyncNode.Checked = ThreeStateBool.False;
                    asyncNode.Icon = Icon.Accept;
                    if (Convert.ToBoolean(tRow[0]["is_leaf"]))
                    {
                        asyncNode.Leaf = true;
                    }
                    nodes.Add(asyncNode);
                }

            }
        }
        return nodes;
    }

    #endregion
}
